6 #define D(x) cout << #x " = " << (x) << endl
11 typedef pair
<int, int> point
;
13 int dist(int x1
, int y1
, int x2
, int y2
){
14 int dx
= abs(x1
- x2
);
15 int dy
= abs(y1
- y2
);
18 int sum(const vector
<point
> &p
){
19 int n
= p
.size(), ans
= 0;
20 for (int i
= 0; i
< n
; ++i
){
21 for (int j
= i
+ 1; j
< n
; ++j
){
22 ans
+= dist(p
[i
].first
, p
[i
].second
, p
[j
].first
, p
[j
].second
);
33 for (int i
= 0; i
< rows
; ++i
){
34 for (int j
= 0; j
< cols
; ++j
){
36 if (mat
[i
][j
] == 'M') a
.push_back(point(i
, j
));
37 if (mat
[i
][j
] == 'S') b
.push_back(point(i
, j
));
41 cout
<< sum(a
) << " " << sum(b
) << endl
;